/*jslint maxerr:10000 */
var host_list = ['http://www.helloweb.com.au'];
function HelloWeb(){

}
HelloWeb.prototype = {
        window_source :'barcode',
        //please check http://developer.appcelerator.com/question/120964/sporadic-server-error-a-connection-failure-occurred
        //for enable_keep_alive setting.
        set_enable_keep_alive:true,//set  this to fix HTTP request error.
        host_list:host_list,
        version:'0.0',
        version_increment:'1',
        //file_base_url : media_host,
        default_time_out:60000,
        default_download_time_out:120000,
        default_time_zone_offset:0,
        count_for_job_query : 10,        
        screen_width:Titanium.Platform.displayCaps.platformWidth,
        screen_height:Titanium.Platform.displayCaps.platformHeight,
        file_directory : Ti.Filesystem.applicationDataDirectory,
        login_background_image : 'login_bg.png',
        background_image : 'bg2.jpg',
        job_list_row_background_color:'#EAF0F7',//set odd row background color
        font_color : '#000',
        selected_value_font_color:'#336699',
        hint_text_font_color:'#333',
        hint_text_font_opacity:0.3,
        font_size : 18,
        font_weight : 'bold',
        font_family : 'Helvetica Neue',
        normal_font_size : 16,
        middle_font_size:14,
        small_font_size : 12,
        section_header_title_font_color:'#4D576D',
        section_header_title_shadow_color:'#FAFAFA',
        section_header_title_shadow_offset:{
                x:0, 
                y:1
        },
        table_view_row_number_label_background_color:'#99A9BD',
        month_list : ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
        day_list : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
        minute_list : ['00','15','30','45'],
        default_table_view_row_height : 45,
        default_gps_location_update_interval : 2*60*1000,//mico seconds,
        tool_bar_height:44,
        tool_bar_background_color:'#CAC9CF',
        default_tool_bar_background_color:'#8294AD',
        calendar_week_name_abbr_list:['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
        calendar_font_color:'#fff',//'#1B313F'
        job_default_status_colour:'#ccc',
        job_list_description_default_colour:'#CAC9CF',
        default_thumb_image_width:72,//default thumb image width
        default_camera_photo_width:720,
        default_camera_photo_height:960,
        maximum_audio_length:300,//5 minute
        maximum_video_length:90000,//90 seconds
        materials_type_code:6,//this is code for materials/supplies type code in job_asset_type_code
        action_list:(Titanium.Platform.osname == 'ipad')?['Phone','SMS','Email','Notification','Cancel','']:['Phone','SMS','Email','Notification','Cancel'],
        contact_source_list:['Client Contacts','Site Contacts','Manager Users','Phone Book'],
        modal_message_window:null,
        progress_bar:null,
        actInd:null,
        close_btn:null,//close model window
        loading_actInd:null,
        main_page_obj:null,//the object of main page.
        no_result_text_for_drag_down:'No Result\n\n (Drag Down To Download)',  
        default_main_menu_button_index:0,
        ipad_button_reduce_length_in_tableview:80,
        iphone_button_reduce_length_in_tableview:18,
        gst_default_name:'GST',
        set_animated_for_ios7:false,
        set_table_view_header_backgroundcolor:'#EFEFF3',//'#EAF0F7',
        default_udid:123456,
        default_device_type:'ios',
        max_number_camera_take_photo_or_video:9,
        tool_bar_color_in_ios_7:'#C2C1C6',
        scanditsdk_key:'K6MCiJ3iEeOX7ZQuj3yOcCOfVhCBR1b9o+pIddfCrUg',
        get_db_name:function(){
                return 'fieldteam.'+this.version+'.'+this.version_increment;
        },
        //get platform information
        get_platform_info:function(){
                return 'Platform Name:'+Ti.Platform.name+',model:'+Titanium.Platform.model+',version:'+Titanium.Platform.version;
        },
        is_simulator:function(){
                var self = this;
                try{
                        if(Titanium.Platform.model == 'Simulator'){
                                return true;
                        }
                        return false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_simulator');
                        return false;
                }                   
        },
        /**
         *  init function
         */
        init:function(){
                var self = this;
                try{         
                        self.init_auto_release_pool(null);
                        self.data = [];
                        self.init_navigation_bar();
                        self.init_vars();
                        self.init_table_view();
                        self.init_no_result_label();                           
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - init');
                        return;
                }                
        },    
        /**
         * init auot release pool,
         * create an array to save all objects
         */
        init_auto_release_pool:function(win){
                var self = this;
                try{
                        if(win != undefined){
                                win.is_close_all_window = false;
                        }
                        if(win != undefined && win != null){
                                Ti.App.selectWindowObject = win;
                                Ti.App.fireEvent('add_window_to_global_array');                                
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - init_auto_release_pool');
                        return;
                }
        },
        /**
         * click main menu button, and return to index page
         * note: index page push into queue as well, so app need to keep the index page in the queue. 
         *  only pop up other windows.
         */
        close_all_window_and_return_to_menu:function(){
                var self = this;
                try{
                        Ti.App.fireEvent('close_all_window_and_return_to_menu');
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - close_all_window_and_return_to_menu');
                        return;
                }                
        },
        
        process_event_before_close_window:function(){
                var self = this;
                try{                                       
                        if((self.data != undefined) && (self.data != null) && (self.data.length > 0)){
                                for(var m=0,n=self.data.length;m<n;m++){
                                        self.data[m] = null;                                
                                }
                                self.data = [];                                                                                                                              
                        }                                                                      
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - process_event_before_close_window');
                        return;
                }                
        },
        /**
         * close window, or do some extra events before call win.close
         */
        close_window:function(){
                var self = this;
                try{
                        self.process_event_before_close_window();
                        if(!Ti.App.Properties.getBool('ready_remove_all_window_and_return_to_menu')){
                                Ti.App.fireEvent('close_window_from_global_array');
                        }
                }
                catch(err){
                        self.process_simple_error_message(err,self.window_source+' - close_window');
                        return;
                }                     
        },      
        
        /**
         * init variables
         */
        init_vars:function(){},
        /**
         * init navigation bar
         */
        init_navigation_bar:function(right_btn_title,left_btn_title){
                var self = this;
                try{
                        self.nav_left_btn = null;
                        self.nav_right_btn = null;
                        
                        //if button title exist ",", then it means that exist multi buttons on Tabbed bar
                        
                        self.left_buttons_objects = [];
                        self.right_buttons_objects = [];
                        if (Titanium.Platform.name === 'iPhone OS'){
                                if(left_btn_title != undefined){
                                        var left_btn_title_array = left_btn_title.split(',');                                        
                                        if(left_btn_title_array.length <=1){
                                                self.nav_left_btn = Ti.UI.createButton({
                                                        title:left_btn_title,
                                                        style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED                                                     
                                                });
                                        }else{                                                
                                                for(var i=0;i<left_btn_title_array.length;i++){
                                                        switch(left_btn_title_array[i].toLowerCase()){
                                                                case 'main':
                                                                        self.left_buttons_objects.push({
                                                                                name:left_btn_title_array[i].toLowerCase(),
                                                                                image:'/images/icons/home_2_24'+(self.is_ios_7_plus()?'_blue':'')+'.png',
                                                                                width:'50px'
                                                                        });
                                                                        break;
                                                                case 'back':
                                                                        self.left_buttons_objects.push({
                                                                                name:left_btn_title_array[i].toLowerCase(),
                                                                                image:'/images/icons/back_2_24'+(self.is_ios_7_plus()?'_blue':'')+'.png',
                                                                                width:'50px'
                                                                        });
                                                                        break;                                                                        
                                                                default:
                                                                        self.left_buttons_objects.push({
                                                                                name:left_btn_title_array[i].toLowerCase(),
                                                                                title:self.ucfirst(left_btn_title_array[i]),
                                                                                width:'50px'
                                                                        });                                                                        
                                                                        break;
                                                        }
                                                }  
                                                self.nav_left_btn = Titanium.UI.iOS.createTabbedBar({
                                                        labels:self.left_buttons_objects,
                                                        style:Titanium.UI.iPhone.SystemButtonStyle.BAR
                                                });                                   
                                        }                                        
                                        Titanium.UI.currentWindow.setLeftNavButton(self.nav_left_btn);
                                }
                                
                                if((right_btn_title != undefined)&& (right_btn_title != '')){
                                        var right_btn_title_array = right_btn_title.split(',');                                                                                      
                                        if(right_btn_title_array.length <=1){
                                                switch(right_btn_title.toLowerCase()){
                                                        case 'add':
                                                                self.nav_right_btn = Ti.UI.createButton({
                                                                        systemButton:Titanium.UI.iPhone.SystemButton.ADD
                                                                });                                                
                                                                break;
                                                        case 'refresh':
                                                                self.nav_right_btn = Ti.UI.createButton({
                                                                        systemButton:Titanium.UI.iPhone.SystemButton.REFRESH
                                                                });                                                
                                                                break;      
                                                        case 'done':
                                                                self.nav_right_btn = Ti.UI.createButton({
                                                                        systemButton:Titanium.UI.iPhone.SystemButton.DONE
                                                                });                                                                                                                        
                                                                break;   
                                                        case 'save':
                                                                self.nav_right_btn = Ti.UI.createButton({
                                                                        systemButton:Titanium.UI.iPhone.SystemButton.SAVE
                                                                });                                                                                                                        
                                                                break;                                                                 
                                                        default:
                                                                self.nav_right_btn = Ti.UI.createButton({
                                                                        title:right_btn_title,
                                                                        style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
                                                                });                                                
                                                }
                                        }else{
                                                for(var i=0;i<right_btn_title_array.length;i++){
                                                        switch(right_btn_title_array[i].toLowerCase()){                                                                            
                                                                default:
                                                                        self.right_buttons_objects.push({
                                                                                name:right_btn_title_array[i].toLowerCase(),
                                                                                title:self.ucfirst(right_btn_title_array[i]),
                                                                                width:'50px'
                                                                        });                                                                                                                                       
                                                        }
                                                }  
                                                self.nav_right_btn = Titanium.UI.createButtonBar({
                                                        labels:self.right_buttons_objects,
                                                        style:Titanium.UI.iPhone.SystemButtonStyle.BAR
                                                });                                                 
                                        }
                                        Titanium.UI.currentWindow.setRightNavButton(self.nav_right_btn);                                 
                                }                    
                        } 
                        
                        if(self.nav_left_btn != null){
                                self.nav_left_btn.addEventListener('click',function(e){
                                        self.nav_left_btn_click_event(e);
                                });  
                        }
                        if(self.nav_right_btn != null){
                                self.nav_right_btn.addEventListener('click',function(e){
                                        self.nav_right_btn_click_event(e);
                                });       
                        }

                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - init_navigation_bar');
                        return;
                }                        
        },
        /**
         *  init table view
         */
        init_table_view:function(type){
                var self = this;
                try{               
                        if(Titanium.Platform.name=='android') { 
                                self.table_view = Ti.UI.createTableView({
                                        backgroundColor:'#000',
                                        data:self.data,           
                                        minRowHeight:self.default_table_view_row_height
                                });
                                Titanium.UI.currentWindow.add(self.table_view);                                
                        }else{
                                self.table_view = Ti.UI.createTableView({
                                        data:self.data,
                                        style: (((type === undefined) || (self.trim(type) === 'grouped')) && (!self.is_ios_7_plus()))?Ti.UI.iPhone.TableViewStyle.GROUPED:Ti.UI.iPhone.TableViewStyle.PLAIN,                
                                        minRowHeight:self.default_table_view_row_height
                                });
                                Titanium.UI.currentWindow.add(self.table_view);
                        }
                        self.table_view.addEventListener('click',function(e){
                                self.table_view_click_event(e);
                        });                
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - init_table_view');
                        return;
                }                
        },
        /**
         *  show no result text if query result is null
         */
        init_no_result_label:function(){
                var self = this;
                try{
                        self.no_result_label = Ti.UI.createLabel({
                                background:'transparent',
                                text:'No Result',
                                color:'#336699',
                                width:'auto',
                                textAlign:'center',
                                font:{
                                        fontSize:20,
                                        fontWeight:'bold'
                                }
                        });
                        Titanium.UI.currentWindow.add(self.no_result_label);  
                        if(self.data.length > 0){
                                self.no_result_label.visible = false;
                        }else{
                                self.no_result_label.visible = true;
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - init_no_result_label');
                        return;
                }
        },
        /**
         *  table view click event
         */
        table_view_click_event:function(){},
        /**
         *  navigation bar's right button click event
         */
        nav_right_btn_click_event:function(e){},
        /**
         *  navigation bar's left button click event
         */
        nav_left_btn_click_event:function(e){
                var self = this;
                try{
                        if(e.index == self.default_main_menu_button_index){//menu menu
                                self.close_all_window_and_return_to_menu();          
                        }else{//back button
                                Titanium.UI.currentWindow.is_close_all_window = false;
                                Titanium.UI.currentWindow.close();
                        }                               
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - nav_left_btn_click_event');
                        return; 
                }             
        },   
        /**
         *  some streets haven't street type. I have set street is full street.
         *  But street still only display street name (without street type).
         *  Reset street with this function. (this function support all street style.)          
         */ 
        display_correct_street:function(street,street_type){
                var self = this;
                try{
                        if((street === undefined) || (street === null) ||(street === '')){
                                return '';
                        }
                        if((street_type === undefined) || (street_type === null) ||(street_type === '')){
                                return street;
                        }                        
                        var temp_street = street.toLowerCase();
                        var temp_street_type = street_type.toLowerCase();
                        var temp_array = temp_street.split(' ');
                        if(temp_array.length > 0){
                                if(temp_array[temp_array.length-1] === temp_street_type){
                                        return street;
                                }else{
                                        if(temp_street_type == '(blank)'){
                                                return street;
                                        }else{                                       
                                                return street+' '+street_type;
                                        }
                                }
                        }
                        return street;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - display_correct_street');
                        return '';
                }
        },        
        /**
         * display model indicator window
         */
        display_indicator:function(message,has_progress_bar,has_cancel_btn){    
                var self = this;
                function _create_model_message_window(message,has_progress_bar,has_cancel_btn){
                        try{
                                if(self.is_iphone_os()){
                                        //for iphone and ipad
                                        self.modal_message_window = Ti.UI.createWindow({
                                                backgroundColor:'#999',
                                                fullscreen:false,
                                                opacity:0.8
                                        });
                                        self.sub_modal_message_window = Titanium.UI.createView({
                                                backgroundColor:'#113D69',
                                                borderWidth:4,
                                                borderColor:'#999',
                                                height:120,
                                                width:280,
                                                borderRadius:8
                                        });
                                        self.modal_message_window.add(self.sub_modal_message_window);
                                        if(has_progress_bar){
                                                self.actInd = Ti.UI.createActivityIndicator({
                                                        font:{
                                                                fontSize:self.font_size,
                                                                fontWeight:self.font_weight
                                                        },
                                                        color:'#fff',
                                                        message:message,
                                                        width:'auto',
                                                        height:'auto'
                                                });
                                                if(has_cancel_btn != undefined && has_cancel_btn != null && has_cancel_btn == true){
                                                        self.actInd.top = 30;
                                                }
                                                self.sub_modal_message_window.add(self.actInd);
                                                self.actInd.show();
                                                self.progress_bar=Titanium.UI.createProgressBar({
                                                        width:200,
                                                        min:0,
                                                        max:1,
                                                        value:0,
                                                        height:50,
                                                        color:'#888',
                                                        style:Titanium.UI.iPhone.ProgressBarStyle.PLAIN,
                                                        font:{
                                                                fontSize:14, 
                                                                fontWeight:'bold'
                                                        },
                                                        bottom:(has_cancel_btn != undefined && has_cancel_btn != null && has_cancel_btn == true)?38:15
                                                });
                                                self.sub_modal_message_window.add(self.progress_bar);
                                                self.progress_bar.show();
                                                if(has_cancel_btn != undefined && has_cancel_btn != null && has_cancel_btn == true){
                                                        self.actInd_cancel_line=Ti.UI.createView({
                                                                width:280,
                                                                height:1,
                                                                bottom:45,
                                                                borderWidth:1,
                                                                borderColor:'#ccc'
                                                        });                                      
                                                        self.sub_modal_message_window.add(self.actInd_cancel_line);                                                        
                                                        self.actInd_cancel_btn=Titanium.UI.createButton({
                                                                width:200,
                                                                height:40,
                                                                bottom:5,
                                                                title:'Cancel',
                                                                color:'#fff',
                                                                font:{
                                                                        fontSize:self.font_size,
                                                                        fontWeight:self.font_weight
                                                                }                                                                
                                                        });
                                                        self.sub_modal_message_window.add(self.actInd_cancel_btn);      
                                                        self.actInd_cancel_btn.addEventListener('click',function(e){
                                                                Ti.App.Properties.setBool('is_hide_indicator',true);
                                                        });
                                                }
                                        }else{
                                                self.actInd = Ti.UI.createActivityIndicator({
                                                        font:{
                                                                fontSize:self.font_size,
                                                                fontWeight:self.font_weight
                                                        },
                                                        color:'#fff',
                                                        message:message,
                                                        width:'auto',
                                                        height:'auto'
                                                });
                                                if(has_cancel_btn != undefined && has_cancel_btn != null && has_cancel_btn == true){
                                                        self.actInd.top = 30;
                                                }                                                
                                                self.sub_modal_message_window.add(self.actInd);
                                                self.actInd.show();
                                                if(has_cancel_btn != undefined && has_cancel_btn != null && has_cancel_btn == true){
                                                        self.actInd_cancel_line=Ti.UI.createView({
                                                                width:280,
                                                                height:1,
                                                                bottom:45,
                                                                borderWidth:1,
                                                                borderColor:'#ccc'
                                                        });                                      
                                                        self.sub_modal_message_window.add(self.actInd_cancel_line);
                                                        self.actInd_cancel_btn=Titanium.UI.createButton({
                                                                width:200,
                                                                height:40,
                                                                bottom:5,
                                                                title:'Cancel',
                                                                color:'#fff',
                                                                font:{
                                                                        fontSize:self.font_size,
                                                                        fontWeight:self.font_weight
                                                                } 
                                                        });
                                                        self.sub_modal_message_window.add(self.actInd_cancel_btn); 
                                                        self.actInd_cancel_btn.addEventListener('click',function(e){
                                                                Ti.App.Properties.setBool('is_hide_indicator',true);
                                                        });                                                        
                                                }                                                
                                        }
                                }else{
                                        self.actInd = Ti.UI.createActivityIndicator({
                                                font:{
                                                        fontSize:self.font_size,
                                                        fontWeight:self.font_weight
                                                },
                                                color:'#fff',
                                                message:message,
                                                width:'auto',
                                                height:'auto'
                                        });
                                        self.actInd.show();
                                }
                        }catch(err){
                                self.process_simple_error_message(err,self.window_source+' - init');
                                return;
                        }
                }
                
                try{
                        if((has_progress_bar === null) || (has_progress_bar === undefined)){
                                has_progress_bar = false;
                        } 
                        _create_model_message_window(message,has_progress_bar,has_cancel_btn);
                        if(self.is_iphone_os()){
                                self.modal_message_window.open({
                                        modal:false
                                });
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - display_indicator');
                        return;
                }
        },
        /**
         * get selected currency in setting value
         */
        get_selected_currency:function(){
                var self = this;
                try{                
                        var tempCurrency = Ti.App.Properties.getString('selected_currency');
                        tempCurrency = (tempCurrency== null)?'':tempCurrency;
                        tempCurrency = (self.trim(tempCurrency) == '')?'$':tempCurrency;
                        return tempCurrency;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_selected_currency');
                        return '';
                }                
        },       
        /**
         *format number to currency
         */
        currency_formatted:function(amount){
                var self = this;
                try{
                        if(amount == ''){
                                return '0.00';
                        }
                        var i = parseFloat(amount);
                        if(isNaN(i)) {
                                return '0.00';
                        }
                        //i = Math.abs(i);
                        i = Math.round(i*100)/100;
                        //                i = parseInt((i) * 100);
                        //                i = i / 100;
                        var s = i+'';
                        if(s.indexOf('.') < 0) {
                                s += '.00';
                        }
                        if(s.indexOf('.') == (s.length - 2)) {
                                s += '0';
                        }
                        return s;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - currency_formatted');
                        return '';
                }                 
        },              
        /**
         * update indicator message
         */
        update_message:function(message){
                var self = this;
                try{
                        if(self.is_iphone_os()){
                                if(self.modal_message_window != null){
                                        if(self.actInd != null){
                                                self.actInd.message = message;
                                        }
                                }
                        }else{
                                if(self.actInd != null){
                                        self.actInd.message = message;
                                }                                
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - update_message');
                        return;
                }                        
        },
        /**
         * update progress bar value
         */
        update_progress:function(new_progress,has_progress_bar){
                var self = this;
                try{
                        if(self.is_iphone_os()){
                                if(self.modal_message_window != null){
                                        if((has_progress_bar)&&(self.progress_bar != null)){
                                                self.progress_bar.value = new_progress;
                                        }
                                }
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - update_progress');
                        return;
                }                        
        },
        /**
         * hide indicator window
         */
        hide_indicator:function(){
                var self = this;
                try{
                        if(self.is_iphone_os()){
                                if(self.modal_message_window != null){   
                                        self.modal_message_window.close();
                                        self.modal_message_window = null;
                                        self.sub_modal_message_window = null;                                                                                
                                        if(self.progress_bar != null){
                                                self.progress_bar = null;
                                        }
                                        if(self.actInd != null){
                                                self.actInd = null;
                                        }                                        
                                }
                        }else{
                                if(self.actInd != null){
                                        self.actInd.hide();
                                        self.actInd = null;
                                } 
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - hide_indicator');
                        return;
                }                        
        },
        /**
         * get uniqute array lsit
         */
        get_file_path:function(type,filename){
                var self = this;
                try{
                        var temp_str = '';
                        switch(type){
                                case 'database':
                                        Titanium.include(Ti.App.Properties.getString('base_folder_name')+'database/'+filename);
                                        break;
                                case 'url':
                                        temp_str = Ti.App.Properties.getString('base_folder_name')+filename;
                                        break;
                                case 'image':
                                        temp_str = '/images/'+filename;
                                        break;
                        }
                        return temp_str;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_file_path');
                        return '';
                }                        
        },
        /**
         *  get unique array by old array
         */
        get_unique_array:function(old_array){
                var self = this;
                try{
                        var new_array = [];
                        if(old_array.length <=0){
                                return new_array;
                        }
                        var sorted_arr = old_array.sort();
                        for(var i=0,j=sorted_arr.length;i<j;i++){
                                var flag = false;
                                for(var m=0,n=new_array.length;m<n;m++){
                                        if(new_array[m] === sorted_arr[i]){
                                                flag = true;
                                                break;
                                        }
                                }
                                if(!flag){
                                        new_array.push(sorted_arr[i]);
                                }
                        }
                        return new_array;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_unique_array');
                        return [];
                }                        
        },
        /**
         * set first letter is upper case.
         */
        ucfirst:function(string){
                var self = this;
                try{
                        if((string === null)||(string === undefined) || (string === '')){
                                return '';
                        }else{
                                return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - ucfirst');
                        return '';
                }                        
        },
        /**
         * set first letter of every word is upper case
         */
        ucfirst_for_each:function(string){
                var self = this;
                try{
                        if((string === null)||(string === undefined) || (string === '')){
                                return '';
                        }else{
                                string = string.replace(/^\s+|\s+$/g,"");
                                var str_array = string.split(' ');
                                var result_str = '';
                                for(var i=0;i<str_array.length;i++){
                                        if(i === 0){
                                                result_str+=self.ucfirst(str_array[i]);
                                        }else{
                                                result_str+=' '+self.ucfirst(str_array[i]);
                                        }
                                }
                                return result_str;
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - ucfirst_for_each');
                        return '';
                }                        
        },
        /**
         * get days number of selected year and month
         */
        days_number_of_month:function(iYear,iMonth){
                var self = this;
                try{
                        return 32 - new Date(iYear, iMonth, 32).getDate();
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - days_number_of_month');
                        return 0;
                }                        
        },
        /**
         * get first date of this week by selected year,month, date
         */
        get_the_first_day_of_this_week:function(y,m,d){
                var self = this;
                try{
                        var temp_date = new Date(y,m,d);
                        var sDay = temp_date.getDay();
                        if(sDay === 0){
                                sDay = 7;
                        }
                        var start_temp_date = new Date(temp_date.getTime()-(sDay-1)*24*3600*1000);
                        var sMonth = 0;
                        var sDate = 0;
                        if((start_temp_date.getMonth()+1) <=9){
                                sMonth = '0'+(start_temp_date.getMonth()+1);
                        }else{
                                sMonth = start_temp_date.getMonth()+1;
                        }
                        if(start_temp_date.getDate() <=9){
                                sDate = '0'+start_temp_date.getDate();
                        }else{
                                sDate = start_temp_date.getDate();
                        }
                        return start_temp_date.getFullYear()+'-'+sMonth+'-'+sDate;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_the_first_day_of_this_week');
                        return '';
                }                        
        },
        /**
         * get last date of this week by selected year,month, date
         */        
        get_the_last_day_of_this_week:function(y,m,d){
                var self = this;
                try{
                        var temp_date = new Date(y,m,d);
                        var sDay = temp_date.getDay();
                        var end_temp_date = new Date(temp_date.getTime()+(7-sDay)*24*3600*1000);
                        var sMonth = 0;
                        var sDate = 0;
                        if((end_temp_date.getMonth()+1) <=9){
                                sMonth = '0'+(end_temp_date.getMonth()+1);
                        }else{
                                sMonth = end_temp_date.getMonth()+1;
                        }

                        if(end_temp_date.getDate() <=9){
                                sDate = '0'+end_temp_date.getDate();
                        }else{
                                sDate = end_temp_date.getDate();
                        }

                        return end_temp_date.getFullYear()+'-'+sMonth+'-'+sDate;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_the_last_day_of_this_week');
                        return '';
                }                        
        },
        /**
         * trim string
         */
        trim:function(str){
                var self = this;
                try{
                        if((str === undefined)||(str === null)){
                                return '';
                        }
                        str = ''+str;
                        return str.replace(/^\s*/, "").replace(/\s*$/, "");
                //return str.replace(/^\s+|\s+$/g,"");
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - trim');
                        return '';
                }                        
        },
        /**
         * replace query_str of origin string with replace_str
         */
        replace:function(origin_str,query_str,replace_str){
                var self = this;
                try{
                        if((origin_str === undefined) || (origin_str === null) || (origin_str === '')){
                                return '';
                        }
                        origin_str = origin_str.toString();
                        return origin_str.replace(new RegExp(query_str.toString(), "g"),replace_str.toString());
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - replace');
                }
        },
        /**
         * check address
         * will send request to server and get latitude and longitude of address
         */
        check_address:function(params){
                var self = this;
                try{
                        var xhr = null;
                        if(self.set_enable_keep_alive){
                                xhr = Ti.Network.createHTTPClient({
                                        enableKeepAlive:false
                                });
                        }else{
                                xhr = Ti.Network.createHTTPClient();
                        }
                        xhr.onload = function(){
                                try{
                                        if((xhr.readyState === 4)&&(this.status === 200)){
                                                if(self.return_to_login_page_if_user_security_session_changed(this.responseText)){
                                                        return;
                                                }                                                   
                                                if(self.display_app_version_incompatiable(this.responseText)){
                                                        if(params.hide_indicator){
                                                                self.hide_indicator();
                                                        }                                                        
                                                        return;
                                                }          
                                                Ti.API.info(this.responseText);
                                                var temp_result = JSON.parse(this.responseText);    
                                                if(params.hide_indicator){
                                                        self.hide_indicator();
                                                }                                                        
                                                if((temp_result.error != undefined)&&(temp_result.error.length >0)){                                                
                                                        if((temp_result.suggestions != undefined)&&(temp_result.suggestions.length >0)){
                                                                self.displaySuggestionSuburbList(this.responseText,params);
                                                        }else{                                                                
                                                                var error_string = '';
                                                                for(var i=0,j=temp_result.error.length;i<j;i++){
                                                                        if(i==j){
                                                                                error_string+=temp_result.error[i];
                                                                        }else{
                                                                                error_string+=temp_result.error[i]+'\n';
                                                                        }
                                                                }
                                                                self.show_message(error_string);
                                                        }                                                                                                               
                                                        return;
                                                }else{
                                                        params.latitude = (temp_result.latitude === undefined)?null:temp_result.latitude;
                                                        params.longitude = (temp_result.longitude === undefined)?null:temp_result.longitude;
                                                        params.street_type_id = (temp_result.locality_street_type_id === undefined)?0:temp_result.locality_street_type_id;
                                                        params.suburb_id = (temp_result.locality_suburb_id === undefined)?0:temp_result.locality_suburb_id;
                                                        params.postcode = (temp_result.postcode === undefined)?'':temp_result.postcode;
                                                        self.save_address(params);
                                                }
                                        }else{
                                                if(params.hide_indicator){
                                                        self.hide_indicator();
                                                }
                                                var error_params = {
                                                        message:"Checking address failed.",
                                                        show_message:true,
                                                        message_title:'',
                                                        send_error_email:true,
                                                        error_message:'',
                                                        error_source:self.window_source+' - check_address - xhr.onload - 1',
                                                        server_response_message:this.reponseText
                                                };
                                                self.processXYZ(error_params);                                                  
                                                return;
                                        }                            
                                }catch(e){
                                        if(params.hide_indicator){
                                                self.hide_indicator();
                                        }
                                        error_params = {
                                                message:"Checking address failed.",
                                                show_message:true,
                                                message_title:'',
                                                send_error_email:true,
                                                error_message:e,
                                                error_source:self.window_source+' - check_address - xhr.onload - 2',
                                                server_response_message:this.reponseText
                                        };
                                        self.processXYZ(error_params);  
                                        return;
                                }
                        };
                        xhr.onerror = function(e){
                                if(params.hide_indicator){
                                        self.hide_indicator();
                                }
                                var error_params = {
                                        message:"Checking address failed.",
                                        show_message:true,
                                        message_title:'',
                                        send_error_email:true,
                                        error_message:e,
                                        error_source:self.window_source+' - check_address - xhr.onerror',
                                        server_response_message:this.reponseText
                                };
                                self.processXYZ(error_params);  
                                return;
                        };
                        xhr.setTimeout(self.default_time_out);
                        xhr.open('POST',self.get_host_url()+'update',false);
                        xhr.send({
                                'type':'check_address',
                                'hash':params.user_id,
                                'sub_number':params.sub_number,
                                'unit_number':params.unit_number,
                                'street_number':params.street_number,
                                'street_type':params.street_type,
                                'street':params.street,
                                'suburb':params.suburb,
                                'postcode':params.postcode,
                                'locality_state_id':params.state_id,
                                'locality_country_id':Ti.App.Properties.getString('selected_country_id'),
                                'new_addr':params.new_addr,
                                'new_addr_state_and_country':params.new_addr_state_and_country,
                                'app_security_session':self.is_simulator()?self.default_udid:Titanium.Platform.id,
                                'app_version_increment':self.version_increment,
                                'app_version':self.version,
                                'app_platform':self.get_platform_info()
                        });                        
                }catch(err){
                        self.hide_indicator();
                        self.process_simple_error_message(err,self.window_source+' - check_address');
                        return;
                }
        },
        /**
         *  display suggestion suburb list
         */
        displaySuggestionSuburbList:function(responseText,params){
                var self = this;
                try{
                        var suggestionArray = [];
                        var suggestionLabels = [];
                        var temp_result = JSON.parse(responseText); 
                        for(var i=0,j=temp_result.suggestions.length;i<j;i++){
                                suggestionLabels.push(temp_result.suggestions[i].label);
                                var suggestionSuburb = {
                                        suburb_id:temp_result.suggestions[i].suburb_id,
                                        suburb:temp_result.suggestions[i].suburb,
                                        postcode:temp_result.suggestions[i].postcode
                                };
                                suggestionArray.push(suggestionSuburb);
                        }
                        suggestionLabels.push('Cancel');
                        if(self.is_ipad()){
                                suggestionLabels.push('');
                        }                        
                        var optionDialog = Ti.UI.createOptionDialog({
                                options:suggestionLabels,
                                buttonNames:['Cancel'],
                                destructive:0,
                                cancel:(self.is_ipad()?suggestionLabels.length-2:suggestionLabels.length-1),
                                title:'Please select a suburb.'
                        });
                        optionDialog.show();
                        optionDialog.addEventListener('click',function(evt){        
                                if(suggestionLabels[evt.index] === 'Cancel' || suggestionLabels[evt.index] === ''){
                                }else{
                                        params.suburb_id = suggestionArray[evt.index].suburb_id;
                                        params.suburb = suggestionArray[evt.index].suburb;
                                        params.postcode = suggestionArray[evt.index].postcode;
                                        
                                        var new_addr = params.street_number+',+'+params.street+',+'+params.suburb;
                                        var temp_country = Titanium.App.Properties.getString('selected_country_name');
                                        temp_country = (temp_country === null)?'':temp_country;
                                        var new_addr_state_and_country = '';
                                        if(self.trim(temp_country) != ''){
                                                new_addr_state_and_country = ',+'+params.state+',+'+temp_country;
                                        }else{
                                                new_addr_state_and_country = ',+'+params.state;
                                        }                                
                                        new_addr  = self.replace(new_addr,' ','+');
                                        new_addr_state_and_country  = self.replace(new_addr_state_and_country,' ','+');                                        
                                        params.new_addr = new_addr;
                                        params.new_addr_state_and_country = new_addr_state_and_country;
                                        if(Ti.Network.online){
                                                params.hide_indicator = true;
                                                self.display_indicator('Checking Address ...',true);
                                                self.check_address(params);
                                        }else{
                                                self.save_address(params);  
                                        }
                                }
                        });                        
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - displaySuggestionSuburbList');
                        return;
                }
        },
        /**
         * save address and get latitude,longitude
         */
        save_address:function(params){               
        },
        /**
         * check if it's iphone
         */
        is_iphone_os:function(){
                var self = this;
                try{
                        return (Titanium.Platform.name == 'iPhone OS')?true:false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_iphone_os');
                        return false;
                }           
        },
        /**
         * check if it's iphone 3.2+
         */        
        is_iphone_3_2_plus:function(){
                var self = this;
                try{
                        // add iphone specific tests
                        if (Titanium.Platform.name == 'iPhone OS')
                        {
                                var version = Titanium.Platform.version.split(".");
                                var major = parseInt(version[0],10);
                                var minor = parseInt(version[1],10);

                                // can only test this support on a 3.2+ device
                                if (major > 3 || (major == 3 && minor > 1))
                                {
                                        return true;
                                }
                        }
                        return false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_iphone_3_2_plus');
                        return false;
                }                                   
        },
        /**
         * check if it's iphone 4
         */        
        is_iphone_5:function(){
                var self = this;
                try{
                        if (Titanium.Platform.name == 'iPhone OS'){
                                if (Ti.Platform.displayCaps.density == 'high'){
                                        if(Ti.Platform.displayCaps.platformHeight == 568){
                                                return true;
                                        }        
                                }
                        }
                        return false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_iphone_5');
                        return false;
                }                                   
        },
        
        is_iphone_4:function(){
                var self = this;
                try{
                        if (Titanium.Platform.name == 'iPhone OS'){                                
                                if (Ti.Platform.displayCaps.density == 'high'){
                                        if(Ti.Platform.displayCaps.platformHeight == 480){
                                                return true;
                                        }        
                                }
                        }
                        return false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_iphone_4');
                        return false;
                }                                   
        },        
        
        is_ios_4_plus:function(){
                var self = this;
                try{
                        if (Titanium.Platform.name == 'iPhone OS'){
                                var version = Titanium.Platform.version.split(".");
                                Ti.API.info('version:'+version);
                                var major = parseInt(version[0],10);

                                // can only test this support on a 3.2+ device
                                if (major >= 4){
                                        return true;
                                }
                        }
                        return false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_ios_4_plus');
                        return false;
                }                                   
        },        
      
        is_ios_7_plus:function(){
                var self = this;
                try{
                        // iOS-specific test
                        if (Titanium.Platform.name == 'iPhone OS')
                        {
                                var version = Titanium.Platform.version.split(".");
                                var major = parseInt(version[0],10);

                                // Can only test this support on a 3.2+ device
                                if (major >= 7)
                                {
                                        return true;
                                }
                        }
                        return false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_ios_7_plus');
                        return false;
                }                     
        },
        /**
         * check if it's ipad
         */        
        is_ipad:function(){
                var self = this;
                try{
                        return (Titanium.Platform.osname == 'ipad')?true:false;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - is_ipad');
                        return false;
                }                                   
        },
        /*
         *set text field style for ios7
         */
        set_text_field_for_ios_7:function(object){
                var self = this;
                try{
                        if(self.is_ios_7_plus()){
                                object.borderWidth = 1;
                                object.borderColor = '#ccc';
                                object.borderRadius=5;
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - set_text_field_for_ios_7');
                        return;
                }                   
        },
        /**
         * get seconds value by time string
         */        
        get_seconds_value_by_time_string:function(date_string){
                var self = this;
                try{
                        if((date_string === undefined)||(date_string === null)||(date_string === '')||(date_string === 0)){
                                return 0;
                        }
                        var date_array1 = date_string.split(' ');
                        if(date_array1.length ==1){
                                date_array1.push('00:00:00');
                        }
                        var date_array2 = date_array1[0].split('-');
                        var date_array3 = date_array1[1].split(':');
                        var d_y = parseInt(date_array2[0],10);
                        var d_m = parseInt(date_array2[1],10)-1;
                        var d_d = parseInt(date_array2[2],10);
                        var d_h = parseInt(date_array3[0],10);
                        var d_i = parseInt(date_array3[1],10);
                        var d_s = parseInt(date_array3[2],10);
                        var d = new Date(d_y,d_m,d_d,d_h,d_i,d_s,0);
                        return parseInt(d.getTime()/1000,10);
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_seconds_value_by_time_string');
                        return 0;
                }                                   
        },
        /**
         * display time and date with second
         */          
        display_time_and_date_with_second:function(int_time){
                var self = this;
                try{
                        var scheduled_date = null;
                        if(int_time <= 0){
                                scheduled_date = new Date();
                        }else{
                                scheduled_date = new Date(int_time*1000);
                        }
                        //scheduled_date = self.get_correct_date_and_time(scheduled_date);
                        var scheduled_date_year = scheduled_date.getFullYear();
                        var scheduled_date_month = scheduled_date.getMonth();
                        var scheduled_date_date = scheduled_date.getDate();
                        var scheduled_date_day = scheduled_date.getDay();
                        var scheduled_date_hours = scheduled_date.getHours();
                        var scheduled_from_date_seconds = scheduled_date.getSeconds();
                        var scheduled_from_date_minutes = scheduled_date.getMinutes();
                        var scheduled_from_text = '';
                        scheduled_from_text =
                        self.day_list[scheduled_date_day]+', '+
                        ((scheduled_date_date <=9)?'0'+scheduled_date_date:scheduled_date_date)+' '+
                        self.month_list[scheduled_date_month]+' '+scheduled_date_year+' '+
                        ((scheduled_date_hours <=9)?'0'+scheduled_date_hours:scheduled_date_hours)+':'+
                        ((scheduled_from_date_minutes <= 9)?'0'+scheduled_from_date_minutes:scheduled_from_date_minutes)+':'+scheduled_from_date_seconds;
                        return scheduled_from_text; 
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - display_time_and_date_with_second');
                        return '';
                }                                   
        },        
        /**
         * display time and date
         */            
        display_time_and_date:function(int_time){
                var self = this;
                try{
                        var scheduled_date = null;
                        if(int_time <= 0){
                                scheduled_date = new Date();
                        }else{
                                scheduled_date = new Date(int_time*1000);
                        }
                        //scheduled_date = self.get_correct_date_and_time(scheduled_date);
                        var scheduled_date_year = scheduled_date.getFullYear();
                        
                        var scheduled_date_month = scheduled_date.getMonth();
                        var scheduled_date_date = scheduled_date.getDate();
                        var scheduled_date_day = scheduled_date.getDay();
                        var scheduled_date_hours = scheduled_date.getHours();
                        var scheduled_date_ampm = 'AM';
              
                        if(scheduled_date_hours >= 12){
                                if(scheduled_date_hours > 12){
                                        scheduled_date_hours -= 12;
                                }
                                scheduled_date_ampm = 'PM';
                        }
                        var scheduled_from_date_minutes = scheduled_date.getMinutes();
                        var scheduled_from_text = '';
                        scheduled_from_text =
                        self.day_list[scheduled_date_day]+', '+
                        ((scheduled_date_date <=9)?'0'+scheduled_date_date:scheduled_date_date)+' '+
                        self.month_list[scheduled_date_month]+' '+scheduled_date_year+' '+
                        ((scheduled_date_hours <=9)?'0'+scheduled_date_hours:scheduled_date_hours)+':'+
                        ((scheduled_from_date_minutes <= 9)?'0'+scheduled_from_date_minutes:scheduled_from_date_minutes)+scheduled_date_ampm;
                        return scheduled_from_text;     
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - display_time_and_date');
                        return '';
                }                                   
        },
        
        /**
         * display date
         */            
        display_date_only:function(int_time){
                var self = this;
                try{
                        var scheduled_date = null;
                        if(int_time <= 0){
                                scheduled_date = new Date();
                        }else{
                                scheduled_date = new Date(int_time*1000);
                        }
                        //scheduled_date = self.get_correct_date_and_time(scheduled_date);
                        var scheduled_date_year = scheduled_date.getFullYear();
                        var scheduled_date_month = scheduled_date.getMonth();
                        var scheduled_date_date = scheduled_date.getDate();
                        var scheduled_date_day = scheduled_date.getDay();
                        var scheduled_from_text = '';
                        scheduled_from_text =
                        self.day_list[scheduled_date_day]+', '+
                        ((scheduled_date_date <=9)?'0'+scheduled_date_date:scheduled_date_date)+' '+
                        self.month_list[scheduled_date_month]+' '+scheduled_date_year;
                        return scheduled_from_text; 
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - display_date_only');
                        return '';
                }                                   
        },        
        /**
         * figure out date and time by int value
         */                  
        figure_out_date_and_time:function(int_time,is_long_string){
                var self = this;
                try{
                        if((is_long_string === null)||(is_long_string === undefined)){
                                is_long_string = false;
                        }
                        var scheduled_date = null;
                        if(int_time <= 0){
                                scheduled_date = new Date();
                        }else{
                                scheduled_date = new Date(int_time*1000);
                        }
                        //scheduled_date = self.get_correct_date_and_time(scheduled_date);
                        var scheduled_date_year = scheduled_date.getFullYear();
                        var scheduled_date_month = scheduled_date.getMonth();
                        var scheduled_date_date = scheduled_date.getDate();
                        var scheduled_date_day = scheduled_date.getDay();
                        var scheduled_date_hours = scheduled_date.getHours();
                        var scheduled_date_ampm = 'AM';
                        if(scheduled_date_hours >= 12){
                                if(scheduled_date_hours > 12){
                                        scheduled_date_hours -= 12;
                                }
                                scheduled_date_ampm = 'PM';
                        }
                        var scheduled_from_date_minutes = scheduled_date.getMinutes();
                        var scheduled_from_text = '';
                        if(!is_long_string){
                                scheduled_from_text =
                                self.day_list[scheduled_date_day]+'\n'+
                                ((scheduled_date_hours <=9)?'0'+scheduled_date_hours:scheduled_date_hours)+':'+
                                ((scheduled_from_date_minutes <= 9)?'0'+scheduled_from_date_minutes:scheduled_from_date_minutes)+scheduled_date_ampm+' \n '+
                                ((scheduled_date_date <=9)?'0'+scheduled_date_date:scheduled_date_date)+'-'+
                                self.month_list[scheduled_date_month]+'-'+scheduled_date_year;
                        }else{
                                scheduled_from_text =
                                self.day_list[scheduled_date_day]+' '+
                                ((scheduled_date_hours <=9)?'0'+scheduled_date_hours:scheduled_date_hours)+':'+
                                ((scheduled_from_date_minutes <= 9)?'0'+scheduled_from_date_minutes:scheduled_from_date_minutes)+scheduled_date_ampm+' '+
                                ((scheduled_date_date <=9)?'0'+scheduled_date_date:scheduled_date_date)+'-'+
                                self.month_list[scheduled_date_month]+'-'+scheduled_date_year;
                        }
                        return scheduled_from_text;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - figure_out_date_and_time');
                        return '';
                }                                   
        },
        /**
         *  check email is valid or not
         */
        check_valid_email:function(email){
                var self = this;
                try{
                        var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                        if(!filter.test(email)){
                                return false;
                        }
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_valid_email');
                        return false;
                }                                   
        },
        /**
         *  remove all charaters from a string
         */        
        remove_all_charaters_from_string:function(phone_number){
                var self = this;
                try{
                        var m_strOut = new String(phone_number); 
                        m_strOut = phone_number.replace(/[^0-9]/g, ''); 
                        return m_strOut;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - remove_all_charaters_from_string');
                        return false;
                }                                   
        },        
        /**
         *  check price is valid or not
         */        
        check_valid_price:function(price){
                var self = this;
                try{
                        var filter = /^\d{0,8}\.{0,1}(\d{1,2})?$/;
                        if (!filter.test(price)) {
                                return false;
                        }                        
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_valid_price');
                        return false;
                }                                   
        },
        /**
         *  check phone number is valid or not
         */        
        check_valid_phone_number:function(phone_number){
                var self = this;
                try{
                        var filter = /^ *[0-9]+ *$/;
                        if (!filter.test(phone_number)) {
                                return false;
                        }
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_valid_phone_number');
                        return false;
                }                                   
        },     
        /**
         *  check integer value is valid or not（only positive integer）
         */               
        check_valid_integer:function(integer_value){
                var self = this;
                try{
                        var filter = /^[0-9]*$/;
                        if (!filter.test(integer_value)) {
                                return false;
                        }                        
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_valid_integer');
                        return false;
                }                
        },
        /**
         *  check integer value is valid or not（negative integer and  positive integer）
         */               
        check_valid_negative_and_positive_integer:function(integer_value){
                var self = this;
                try{
                        var filter = /^-?[0-9]*$/;
                        if (!filter.test(integer_value)) {
                                return false;
                        }                        
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_valid_negative_and_positive_integer');
                        return false;
                }                
        },        
        
        /**
         * remove all character and symbol , only keep number
         */
        remove_all_character_and_symbol_except_number:function(str){
                var self = this;
                try{
                        if(self.trim(str) == ''){
                                return '';
                        }
                        var new_str_array = [];
                        for(var i=0,j=str.length;i<j;i++){
                                if(((str[i]) >= '0') && (str[i]<=9)){
                                        new_str_array.push(str[i]); 
                                }
                        }
                        if(new_str_array.length > 0){
                                return new_str_array.join('');
                        }else{
                                return '';
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - remove_all_character_and_symbol_except_number');
                        return '';
                }                
        },
        /*
         * get the milliseoonds from 1970/1/1
         */
        get_date_string_by_milliseconds:function(intTime){
                var self = this;
                try{
                        var tempDate = new Date(intTime);
                        var second = tempDate.getSeconds();
                        if(second<=9){
                                second = '0'+second+'';
                        }
                        var minute = tempDate.getMinutes();
                        if(minute <= 9){
                                minute = '0'+minute+'';
                        }
                        var hour = tempDate.getHours();
                        if(hour <= 9){
                                hour = '0'+hour+'';
                        }
                        var date = tempDate.getDate();
                        date = (date<=9)?'0'+(date):(date);
                        var month = tempDate.getMonth();
                        month = (month+1<=9)?'0'+(month+1):(month+1);
                        var year = tempDate.getFullYear();
                        return self.display_time_and_date(self.get_seconds_value_by_time_string(year+'-'+month+'-'+date+' '+hour+':'+minute+':'+second));
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_date_string_by_milliseconds');
                        return '';
                }                                   
        },
        /**
         * set field width in table view row
         */
        set_a_field_width_in_table_view_row:function(){
                var self = this;
                try{
                        return self.screen_width/2;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - set_a_field_width_in_table_view_row');
                        return 0;
                }                                   
        },
        /*
         *create folder, if folder name is mulit folder ,e.g. job/8, then create parent folder and sub folder
         */
        create_directory:function(folder_name){
                var self = this;
                try{
                        //create sub folder
                        var folder = null;
                        var file_name_array = folder_name.split('/');

                        for(var i=0,j=file_name_array.length;i<j;i++){
                                if(i>0){
                                        var m = 0;
                                        var temp_folder_path = '';
                                        while(m<i){
                                                temp_folder_path += '/'+file_name_array[m];
                                                m++;
                                        }
                                        folder = Ti.Filesystem.getFile(self.file_directory+temp_folder_path,file_name_array[i]);
                                }else{
                                        folder = Ti.Filesystem.getFile(self.file_directory,file_name_array[i]);
                                }
                                if(!folder.exists()){
                                        if(!folder.createDirectory()){
                                                return false;
                                        }
                                }
                        }
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - create_directory');
                        return false;
                }                                   
        },        
        /*
         *triger sms,email,phone,push notification events
         */
        action_events:function(type,action_type,selected_job_id,selected_job_reference_number,recipients){
                var self = this;
                try{
                        switch(action_type){
                                case 'call'://phone call/
                                        var phone_number = '';
                                        var display_name = '';
                                        var display_phone_number = '';
                                        var result = JSON.parse(recipients);
                                        if((result === null)||(result === undefined)||(result === '')){
                                                return;
                                        }
                                        else{
                                                phone_number = result[0].content;
                                                display_phone_number = result[0].display_content;
                                                display_name = result[0].name;
                                        }
                                        if(phone_number === ''){
                                                return;
                                        }
                                        var error_info = [];

                                        //check subject
                                        if(error_info.length > 0){
                                                self.show_message(error_info.join('\n'));
                                                return;
                                        }else{
                                                if(!Ti.Network.online){
                                                        self.show_message(L('message_offline'),L('message_unable_to_connect'));
                                                        return;
                                                }else{
                                                        Ti.Platform.openURL('tel:'+phone_number);                                                       
                                                        var _selected_user_id = Ti.App.Properties.getString('current_login_user_id');
                                                        var _selected_user_name = Ti.App.Properties.getString('current_login_user_name');
                                                        var _selected_company_id = Ti.App.Properties.getString('current_company_id');
                                                        var xhr = null;
                                                        if(self.set_enable_keep_alive){
                                                                xhr = Ti.Network.createHTTPClient({
                                                                        enableKeepAlive:false
                                                                });
                                                        }else{
                                                                xhr = Ti.Network.createHTTPClient();
                                                        }
                                                        xhr.onload = function(){
                                                                try{
                                                                        if((xhr.readyState === 4)&&(this.status === 200)){
                                                                                if(self.return_to_login_page_if_user_security_session_changed(this.responseText)){
                                                                                        return;
                                                                                }                                                                                   
                                                                                if(self.display_app_version_incompatiable(this.responseText)){
                                                                                        return;
                                                                                }                                                                           
                                                                                if(this.responseText != '[]'){
                                                                                        var temp_result = JSON.parse(this.responseText);
                                                                                        self.update_selected_tables(null,self.ucfirst(type)+'ContactHistory',temp_result);
                                                                                        self.update_selected_tables(null,self.ucfirst(type)+'ContactHistoryRecipient',temp_result);
                                                                                }
                                                                        }else{
                                                                                var params = {
                                                                                        message:'Phone call failed.',
                                                                                        show_message:false,
                                                                                        message_title:'',
                                                                                        send_error_email:true,
                                                                                        error_message:'',
                                                                                        error_source:self.window_source+' - action_events - xhr.onload -1',
                                                                                        server_response_message:this.reponseText
                                                                                };
                                                                                self.processXYZ(params);                                                                                  
                                                                                return;
                                                                        }
                                                                }catch(e){
                                                                        params = {
                                                                                message:'Phone call failed.',
                                                                                show_message:false,
                                                                                message_title:'',
                                                                                send_error_email:true,
                                                                                error_message:e,
                                                                                error_source:self.window_source+' - action_events - xhr.onload -2',
                                                                                server_response_message:this.reponseText
                                                                        };
                                                                        self.processXYZ(params);                                                                         
                                                                        return;
                                                                }
                                                        };
                                                        xhr.onerror = function(e){
                                                                var params = {
                                                                        message:'Phone call failed.',
                                                                        show_message:false,
                                                                        message_title:'',
                                                                        send_error_email:true,
                                                                        error_message:e,
                                                                        error_source:self.window_source+' - action_events - xhr.onerror',
                                                                        server_response_message:this.reponseText
                                                                };
                                                                self.processXYZ(params);                                                                 
                                                                return;
                                                        };
                                                        xhr.onsendstream = function(e){
                                                        //self.update_progress(e.progress,true);
                                                        };
                                                        xhr.setTimeout(self.default_time_out);
                                                        xhr.open('POST',self.get_host_url()+'update',false);
                                                        xhr.send({
                                                                'type':'action_send_phone',
                                                                'hash':_selected_user_id,
                                                                'company_id':_selected_company_id,
                                                                'manager_user_id':_selected_user_id,
                                                                'job_id':selected_job_id,
                                                                'quote_id':selected_job_id,
                                                                'contact_type_code':1,
                                                                'description':_selected_user_name+' call '+display_name+' '+display_phone_number,
                                                                'status_code':1,
                                                                'job_type':type,
                                                                'app_security_session':self.is_simulator()?self.default_udid:Titanium.Platform.id,
                                                                'app_version_increment':self.version_increment,
                                                                'app_version':self.version,
                                                                'app_platform':self.get_platform_info()
                                                        });
                                                }
                                        }
                                        break;
                                case 'sms'://sms
                                        var sms_win = Titanium.UI.createWindow({
                                                title:'SMS',
                                                url:self.get_file_path('url','action/sms2.js'),
                                                type:type,
                                                source:'sms',
                                                recipients:recipients,
                                                contact_type_code:2,
                                                job_id:selected_job_id,
                                                job_reference_number:selected_job_reference_number
                                        });
                                        Ti.UI.currentTab.open(sms_win,{
                                                animated:(self.is_ios_7_plus() && !self.set_animated_for_ios7)?false:true
                                        });
                                        break;
                                case 'email'://email
                                        Ti.App.Properties.setString('attachments_string',JSON.stringify([]));
                                        var email_win = Titanium.UI.createWindow({
                                                title:'Email',
                                                url:self.get_file_path('url','action/email2.js'),
                                                type:type,
                                                source:'email',
                                                recipients:recipients,
                                                contact_type_code:3,
                                                job_id:selected_job_id,
                                                job_reference_number:selected_job_reference_number
                                        });
                                        Ti.UI.currentTab.open(email_win,{
                                                animated:(self.is_ios_7_plus() && !self.set_animated_for_ios7)?false:true
                                        });
                                        break;
                                case 'push'://push notification
                                        var push_notifiaction_win = Titanium.UI.createWindow({
                                                title:'Push Notification',
                                                url:self.get_file_path('url','action/push_notification.js'),
                                                type:type,
                                                source:'push_notification',
                                                recipients:recipients,
                                                contact_type_code:4,
                                                job_id:selected_job_id,
                                                job_reference_number:selected_job_reference_number
                                        });
                                        Ti.UI.currentTab.open(push_notifiaction_win,{
                                                animated:(self.is_ios_7_plus() && !self.set_animated_for_ios7)?false:true
                                        });
                                        break;                                               
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - action_events');
                        return;
                }                    
        },        
        /**
         * check and set object's focus
         */
        check_and_set_object_focus:function(data_index,row_index,child_index){
                var self = this;
                try{
                        if((self.table_view.data[data_index] != undefined) && (self.table_view.data[data_index] != null)){
                                if((self.table_view.data[data_index].rows[row_index] != undefined) && (self.table_view.data[data_index].rows[row_index] != null)){
                                        if((self.table_view.data[data_index].rows[row_index].children[child_index] != undefined) && (self.table_view.data[data_index].rows[row_index].children[child_index] != null)){
                                                self.table_view.data[data_index].rows[row_index].children[child_index].focus();
                                        }
                                }
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_and_set_object_focus');
                }
        },
        /**
         *  process error info
         */
        process_error_message:function(e,is_show,title){
                var self = this;
                //self.hide_indicator();      
                var is_debug = false;
                var default_host = self.get_host();
                for(var i=0,j=self.major_version_host_list.length;i<j;i++){
                        if(default_host == self.major_version_host_list[i]){
                                is_debug = true;
                                break;
                        }
                }
                if((is_debug) || ((is_show != undefined) && (is_show))){
                        var alertDialog = Titanium.UI.createAlertDialog({
                                title:(title === undefined)?L('message_warning'):title,
                                message:e,
                                buttonNames:['Close']
                        });
                        alertDialog.show();
                }
                if((self.nav_left_btn != undefined) && (self.nav_left_btn != null)){
                        self.nav_left_btn.index = -1;
                }
                return;
        },    
        show_message:function(text,title){
                var alertDialog = Titanium.UI.createAlertDialog({
                        title:(title === undefined)?L('message_warning'):title,
                        message:text,
                        buttonNames:['Close']
                });
                alertDialog.show();           
        },
        process_simple_error_message:function(err, error_source){
                var self = this;
                var is_debug = true;
                var default_host = self.get_host();
                if(default_host == undefined || default_host == null || default_host == ''){
                        is_debug = false;
                }else{
                        for(var i=0,j=self.major_version_host_list.length;i<j;i++){
                                if(default_host == self.major_version_host_list[i]){
                                        is_debug = false;
                                        break;
                                }
                        }
                }               
                var params = {
                        message:err,
                        message_title:'',
                        show_message:is_debug?true:false,
                        send_error_email:true,
                        error_message:err,
                        error_source:error_source,
                        server_response_message:''
                };
                self.processXYZ(params);          
        },
        processXYZ:function(params){
                var self = this;
                if((params.show_message != undefined) && (params.show_message)){
                        var alertDialog = Titanium.UI.createAlertDialog({
                                title:(params.message_title === undefined)?L('message_warning'):params.message_title,
                                message:params.message,
                                buttonNames:['Close']
                        });
                        alertDialog.show();
                }
                if((self.nav_left_btn != undefined) && (self.nav_left_btn != null)){
                        self.nav_left_btn.index = -1;
                }
                if(params.send_error_email != undefined && params.send_error_email && (Ti.Network.online)){
                        //send email to developer
                        try{
                                var xhr = null;
                                if(self.set_enable_keep_alive){
                                        xhr = Ti.Network.createHTTPClient({
                                                enableKeepAlive:false
                                        });
                                }else{
                                        xhr = Ti.Network.createHTTPClient();
                                }
                                xhr.onload = function(){          
                                        Ti.API.info(this.responseText);
                                };
                                xhr.onerror = function(e){
                                        Ti.API.info(e);
                                };
                                xhr.setTimeout(self.default_time_out);
                                xhr.open('POST',self.get_host_url()+'update',false);
                                xhr.send({
                                        'type':'action_send_error_email',
                                        'hash':Ti.App.Properties.getString('current_login_user_id'),
                                        'user_id':Ti.App.Properties.getString('current_login_user_id'),
                                        'company_id':Ti.App.Properties.getString('current_company_id'),
                                        'country_id':Ti.App.Properties.getString('selected_country_id'),
                                        'error_message':params.error_message,
                                        'error_source':params.error_source,
                                        'server_response_message':params.server_response_message,
                                        'subject':'Application Error ',
                                        'app_security_session':self.is_simulator()?self.default_udid:Titanium.Platform.id,
                                        'app_version_increment':self.version_increment,
                                        'app_version':self.version,
                                        'app_platform':self.get_platform_info()
                                });                        
                        }catch(err){
                                return;
                        }
                }
                return;
        }, 
        getObjectSource:function(o) {
                var out = '';
                for (var p in o) {
                        out += p + ': ' + o[p] + '\n';
                }
                return out;
        },        
        
       
        
          
        
        /*
         * return to login page if user's security session is changed
         **/
        return_to_login_page_if_user_security_session_changed:function(responseText){
                var self = this;
                try{
                        Ti.API.info(responseText);
                        var result_result = false;
                        var temp_result  = null;
                        if((responseText != undefined) && (responseText != null) && (responseText != '')){
                                temp_result = JSON.parse(responseText);
                        }else{
                                return false;
                        }
                        //check version error
                        if (!temp_result.access_allowed){                                                               
                                var error_string = '';
                                for(var i=0,j=temp_result.error.length;i<j;i++){
                                        if(i==j){
                                                error_string+=temp_result.error[i];
                                        }else{
                                                error_string+=temp_result.error[i]+'\n';
                                        }
                                }
                                self.process_data_when_logout();
                                self.hide_indicator();
                                var loginWindow = Ti.UI.createWindow({
                                        title:'Login',
                                        url:self.get_file_path('url','login/login.js'),
                                        tab_group_obj:null,
                                        first_login:false
                                });
                                loginWindow.open();                                  
                                self.show_message(error_string);  
                                result_result = true;
                        }
                        return result_result;                        
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - return_to_login_page_if_user_security_session_changed');
                        return false;
                }                
        },
        /**
         * get last updated time text
         */
        get_last_updated_time_text:function(){
                var self = this;
                try{
                        var db = Titanium.Database.open(self.get_db_name());
                        var library_last_updated = 0;
                        var rows = db.execute('SELECT * FROM my_frontend_config_setting where name=?','library_last_updated');
                        if(rows.getRowCount() > 0){
                                if(rows.isValidRow()){
                                        library_last_updated = parseInt(rows.fieldByName('value'),10);
                                }
                        }
                        rows.close();
                        db.close();
                        return self.display_time_and_date(library_last_updated);                       
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_last_updated_time_text');
                        return '';
                }
        },
        /**
         * prcess app version incompatible with backedn
         */
        display_app_version_incompatiable:function(responseText){
                return false;
        //                var self = this;
        //                try{
        //                        Ti.API.info(responseText);
        //                        var result_result = false;
        //                        var temp_result  = null;
        //                        if((responseText != undefined) && (responseText != null) && (responseText != '')){
        //                                temp_result = JSON.parse(responseText);
        //                        }else{
        //                                return false;
        //                        }
        //
        //                        //check version error
        //                        if ((temp_result != undefined) && (temp_result !=null) && (temp_result.app_version_error != undefined)&&(temp_result.app_version_error.length >0)){                                                                        
        //                                var error_string = '';
        //                                for(var i=0,j=temp_result.app_version_error.length;i<j;i++){
        //                                        if(i==j){
        //                                                error_string+=temp_result.app_version_error[i];
        //                                        }else{
        //                                                error_string+=temp_result.app_version_error[i]+'\n';
        //                                        }
        //                                }
        //                                self.hide_indicator();
        //                                self.show_message(error_string);  
        //                                result_result = true;
        //                        }
        //                        //check account token error, e.g username and password have been changed.
        //                        if(!result_result){
        //                                if((temp_result.app_account_error != undefined)&&(temp_result.app_account_error.length >0)){                                                                        
        //                                        error_string = '';
        //                                        for(i=0,j=temp_result.app_account_error.length;i<j;i++){
        //                                                if(i==j){
        //                                                        error_string+=temp_result.app_account_error[i];
        //                                                }else{
        //                                                        error_string+=temp_result.app_account_error[i]+'\n';
        //                                                }
        //                                        }
        //                                        self.hide_indicator();
        //                                        self.show_message(error_string);  
        //                                        result_result = true;
        //                                        Ti.App.Properties.setString('current_login_user_id',0);
        //                                        Ti.App.Properties.setString('current_login_user_name','');
        //                                        Ti.App.Properties.setString('current_company_id',0);
        //                                        Ti.App.Properties.setString('current_login_user_account_token','');                                        
        //                                        var loginWindow = Ti.UI.createWindow({
        //                                                title:'Login',
        //                                                url:self.get_file_path('url','login/login.js'),
        //                                                tab_group_obj:null,
        //                                                first_login:false
        //                                        });
        //                                        loginWindow.open();                                        
        //                                }                                
        //                        }
        //                        return result_result;
        //                }catch(err){
        //                        self.process_simple_error_message(err,self.window_source+' - init');
        //                        return false;
        //                }
        },      
        /**
         * check street type exist in locality_street_type table or not
         */
        check_street_type:function(streetType){
                var self = this;
                try{
                        if(self.trim(streetType) == ''){
                                return false;
                        }
                        var tempStreetType = self.trim(streetType);
                        var db = Titanium.Database.open(self.get_db_name());
                        var rows = db.execute('select id from my_locality_street_type where status_code=1 and name=?',tempStreetType.toUpperCase());
                        if(rows.getRowCount() <=0){
                                rows.close();
                                rows = db.execute('select id from my_locality_street_type where status_code=1 and description=?',tempStreetType.toUpperCase());
                                if(rows.getRowCount() <=0){
                                        rows.close();
                                        db.close();
                                        return false;
                                }else{
                                        rows.close();
                                }
                        }else{
                                rows.close();
                        }
                        db.close();
                        return true;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - check_street_type');
                        return false;                        
                }
        },
        /**
         * get street type id
         */
        return_street_type_id:function(streetType){
                var self = this;
                try{
                        var new_street_type_id = 0;
                        if(self.trim(streetType) == ''){
                                return new_street_type_id;
                        }
                        var tempStreetType = self.trim(streetType);
                        var db = Titanium.Database.open(self.get_db_name());
                        var rows = db.execute('select id from my_locality_street_type where status_code=1 and name=?',tempStreetType.toUpperCase());
                        if(rows.getRowCount() <=0){
                                rows.close();
                                rows = db.execute('select id from my_locality_street_type where status_code=1 and description=?',tempStreetType.toUpperCase());
                                if(rows.getRowCount() <=0){
                                        rows.close();
                                        db.close();
                                        return new_street_type_id;
                                }else{
                                        new_street_type_id = rows.fieldByName('id');
                                        rows.close();
                                }
                        }else{
                                new_street_type_id = rows.fieldByName('id');
                                rows.close();
                        }
                        
                        //check street_type_alias table
                        if(new_street_type_id == 0){
                                rows = db.execute('select id from my_locality_street_type_alias where status_code=1 and name=?',tempStreetType.toUpperCase());
                                if(rows.getRowCount() <=0){
                                }else{
                                        new_street_type_id = rows.fieldByName('id');                                        
                                }  
                                rows.close();
                        }                        
                        db.close();
                        return new_street_type_id;
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - return_street_type_id');
                        return false;                        
                }
        },        
        
        /**
*  get all job id string or quote id string which has been existed in local database
*/
        get_job_id_string:function(type,company_id){
                var self = this;
                try{
                        var db = Titanium.Database.open(self.get_db_name());
                        var job_id_array = [];
                        var rows = db.execute('SELECT * FROM my_'+type+' WHERE company_id=?',company_id);
                        if(rows.getRowCount() > 0){
                                while(rows.isValidRow()){
                                        job_id_array.push(rows.fieldByName('id'));
                                        rows.next();
                                }
                        }
                        rows.close();
                        db.close();
                        if(job_id_array.length > 0){
                                return job_id_array.join(',');
                        }else{
                                return '';
                        }
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - get_job_id_string');
                        return '';
                }
        },
        
        
        //barcode
        update_my_barcode_table:function(db,result){
                var self = this;
                try{
                        if((result === null)||(result.Barcode === undefined)||(result.Barcode === null)||(result.Barcode.length <=0)){
                        }else{
                                for(var i=0,j=result.Barcode.length;i<j;i++){
                                        var data_rows = db.execute('SELECT * FROM my_barcode WHERE id='+result.Barcode[i].id);
                                        var data_row_count = data_rows.getRowCount();
                                        if(data_row_count > 0){
                                                if(data_rows.isValidRow()){      
                                                        var temp_created = data_rows.fieldByName('created');
                                                        var temp_modified = data_rows.fieldByName('modified');                                                
                                                } 
                                                data_rows.close();  
                                                if((result.Barcode[i].created === temp_created)&&((result.Barcode[i].modified === temp_modified))){
                                                }else{
                                                        db.execute('UPDATE my_barcode SET local_id=?,company_id=?,barcode=?,barcode_type=?,job_library_item_id=?,'+
                                                                'status_code=?,created=?,created_by=?,modified_by=?,modified=? WHERE id='+result.Barcode[i].id,
                                                                ((result.Barcode[i].local_id != undefined) && (result.Barcode[i].local_id != null))?result.Barcode[i].local_id:'',
                                                                ((result.Barcode[i].company_id != undefined) && (result.Barcode[i].company_id != null))?result.Barcode[i].company_id:0,
                                                                ((result.Barcode[i].barcode != undefined) && (result.Barcode[i].barcode != null))?result.Barcode[i].barcode:'',
                                                                ((result.Barcode[i].barcode_type != undefined) && (result.Barcode[i].barcode_type != null))?result.Barcode[i].barcode_type:'',
                                                                ((result.Barcode[i].job_library_item_id != undefined) && (result.Barcode[i].job_library_item_id != null))?result.Barcode[i].job_library_item_id:0,
                                                                ((result.Barcode[i].status_code != undefined) && (result.Barcode[i].status_code != null))?result.Barcode[i].status_code:0,
                                                                ((result.Barcode[i].created != undefined) && (result.Barcode[i].created != null))?result.Barcode[i].created:'',
                                                                ((result.Barcode[i].created_by != undefined) && (result.Barcode[i].created_by != null))?result.Barcode[i].created_by:0,
                                                                ((result.Barcode[i].modified_by != undefined) && (result.Barcode[i].modified_by != null))?result.Barcode[i].modified_by:0,
                                                                ((result.Barcode[i].modified != undefined) && (result.Barcode[i].modified != null))?result.Barcode[i].modified:''
                                                                );
                                                }
                                        }else{
                                                data_rows.close();
                                                db.execute('INSERT INTO my_barcode (id,local_id,company_id,barcode,barcode_type,job_library_item_id,'+
                                                        'status_code,created,created_by,modified_by,modified)'+
                                                        'VALUES(?,?,?,?,?,?,?,?,?,?,?)',
                                                        ((result.Barcode[i].id != undefined) && (result.Barcode[i].id != null))?result.Barcode[i].id:0,
                                                        ((result.Barcode[i].local_id != undefined) && (result.Barcode[i].local_id != null))?result.Barcode[i].local_id:'',
                                                        ((result.Barcode[i].company_id != undefined) && (result.Barcode[i].company_id != null))?result.Barcode[i].company_id:0,
                                                        ((result.Barcode[i].barcode != undefined) && (result.Barcode[i].barcode != null))?result.Barcode[i].barcode:'',
                                                        ((result.Barcode[i].barcode_type != undefined) && (result.Barcode[i].barcode_type != null))?result.Barcode[i].barcode_type:'',
                                                        ((result.Barcode[i].job_library_item_id != undefined) && (result.Barcode[i].job_library_item_id != null))?result.Barcode[i].job_library_item_id:0,
                                                        ((result.Barcode[i].status_code != undefined) && (result.Barcode[i].status_code != null))?result.Barcode[i].status_code:0,
                                                        ((result.Barcode[i].created != undefined) && (result.Barcode[i].created != null))?result.Barcode[i].created:'',
                                                        ((result.Barcode[i].created_by != undefined) && (result.Barcode[i].created_by != null))?result.Barcode[i].created_by:0,
                                                        ((result.Barcode[i].modified_by != undefined) && (result.Barcode[i].modified_by != null))?result.Barcode[i].modified_by:0,
                                                        ((result.Barcode[i].modified != undefined) && (result.Barcode[i].modified != null))?result.Barcode[i].modified:''
                                                        );
                                        }
                                }
                        }       
                }catch(err){
                        self.process_simple_error_message(err,self.window_source+' - update_my_barcode_table');
                        return;
                }                        
        }        
};
